<template>
  <div style="max-width: 1280px; margin: 0 auto">
    <div>
      <h1>题目状态界面</h1>
    </div>
    <a-form :model="listParams" :layout="layout">
      <a-form-item field="questionid" label="题号" style="min-width: 240px">
        <a-input v-model="listParams.questionId" placeholder="请输入题号" />
      </a-form-item>
      <a-form-item label="语言" style="min-width: 100px">
        <a-select v-model="listParams.language" style="min-width: 100px">
          <a-option>java</a-option>
          <a-option>python</a-option>
          <a-option>cpp</a-option>
          <a-option>go</a-option>
          <a-option>html</a-option>
        </a-select>
      </a-form-item>
      <a-button type="primary" @click="serchQuestion">搜索</a-button>
      <a-divider size="0" />
    </a-form>
    <a-table
      :columns="columns"
      :data="list"
      :pagination="{
        showTotal: true,
        current: listParams.current,
        pageSize: listParams.pageSize,
        totalNum,
      }"
      @page-change="onPageChange"
    >
      <template #judgeInfo="{ record }">
        {{ JSON.stringify(record.judgeInfo) }}
      </template>
      <template #createTime="{ record }">
        {{ moment(record.createTime).format("YYYY-MM-DD") }}
      </template>
    </a-table>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted, watchEffect } from "vue";
import {
  QuestionControllerService,
  QuestionSubmitControllerService,
} from "../../../generated";
import message from "@arco-design/web-vue/es/message";
import { useRouter } from "vue-router";
import moment from "moment";

const layout = ref("inline");
const form = reactive({
  name: "",
  post: "",
  isRead: false,
});
const onPageChange = (page: number) => {
  listParams.current = page;
};
const router = useRouter();
const practice = (recordId: number) => {
  router.push({
    path: `/question/do/${recordId}`,
  });
};
const serchQuestion = () => {
  listParams.current = 1;
  loadList();
};
const show = ref(true);
let listParams = reactive({
  questionId: undefined,
  language: undefined,
  current: 1,
  pageSize: 7,
  sortField: "createTime",
  sortOrder: "descend",
});
const list = ref([]);
const totalNum = ref(0);
const loadList = async () => {
  const res =
    await QuestionControllerService.listQuestionSubmitQueryVoByPageUsingPost({
      current: 0,
      pageSize: 1000,
      questionId: listParams.questionId,
      language: listParams.language,
      sortField: "createTime",
      sortOrder: "descend",
    });

  if (res.code === 0) {
    list.value = res.data.records;
    totalNum.value = res.data.total;
  } else {
    message.error(res.message);
  }
};
onMounted(() => {
  loadList();
});

watchEffect(() => {
  loadList();
});

const columns = [
  {
    title: "ID",
    dataIndex: "id",
  },
  {
    title: "编程语言",
    dataIndex: "language",
  },
  {
    title: "判题信息",
    slotName: "judgeInfo",
  },
  {
    title: "判题状态",
    dataIndex: "status",
  },
  {
    title: "题目ID",
    dataIndex: "questionId",
  },
  {
    title: "提交者ID",
    dataIndex: "userId",
  },
  {
    title: "创建时间",
    slotName: "createTime",
  },
];
</script>
